/*!
 * @Author: CPS
 * @email: 373704015@qq.com
 * @Date: 2020-08-31 01:33:49
 * @Last Modified by: CPS
 * @Last Modified time: 2020-09-24 16:38:20
 * @Projectname Electron-fileWatcher
 * @file_path Z:\CPS\IDE\SublimeText\3176x32前端\Data\Packages\testt\Plugins\index.js
 * @Filename index.js
 * @ 接收两个参数 参数1：要处理的字符串， 参数2 对应的配置对象，格式：{"syntax":"xxxxx","option":object}
 */
"use strict";
let input = "";
process.stdin.resume();
process.stdin.setEncoding("utf8");

//获取传输过来的数据
process.stdin.on("data", function (data) {
  input += data;
});

// 接收完成后,调用模块处理
process.stdin.on("end", function () {
  //识别要执行的处理操作
  let formater = {
    stylus: require("./stylus/stylusBeatufy.js"),
    pug: require("./pug/pugBeauty.js"),
    html2pug: require("./pug/html2pug.js"),
  };

  try {
    /* 处理配置文件 */
    let options = JSON.parse(process.argv[2]);

    /* 处理配置文件 */
    let mode = process.argv[3].toLowerCase();

    /* 处理并返回结果 */
    let res = formater[mode](input, options);
    process.stdout.write(res);
  } catch (e) {
    process.stdout.write(e);
  }
});
